package com.hzsx;



public class MyThread extends Thread {

    // 重写 run() 方法，编写线程执行体
    @Override
    public void run() {
        for (int i = 1; i < 1000; i++) {
            System.out.println("我是线程的名字: " + Thread.currentThread().getName() + " - " + i);

            try {
                // 让线程睡眠 1 秒
                Thread.sleep(100);
            } catch (InterruptedException e) {
                // 捕获中断异常，处理可能的线程中断
                System.err.println(Thread.currentThread().getName() + " 被中断");
            }
        }
       // super.run(); // 调用父类的 run 方法
    }

    public static void main(String[] args) {
        Thread t1 = new Thread(new MyThread(), "线程A");
        Thread t2 = new Thread(new MyThread(), "线程B");

        // 设置线程优先级
        t1.setPriority(Thread.MAX_PRIORITY); // 最高优先级
        t2.setPriority(Thread.MIN_PRIORITY); // 最低优先级

        // 启动线程
        t1.start();
        t2.start();
    }

             // 同事写的代码
    public static void main110(String[] args) {
        Thread t1 = new Thread(new MyThread(), "线程A");
        Thread t2 = new Thread(new MyThread(), "线程B");
        Thread t3 = new Thread(new MyThread(), "线程C");
        // 设置线程优先级
        t1.setPriority(Thread.MAX_PRIORITY); // 最高优先级
        t2.setPriority(Thread.MIN_PRIORITY); // 最低优先级
        t3.setPriority(Thread.MIN_PRIORITY); // 最低优先级

        // 启动线程
        t1.start();
        t2.start();
    }



}
